package pkg.finanzas;

import java.util.ArrayList;
import java.util.List;
import org.apache.myfaces.trinidad.model.ChartModel;

/**
 *
 * @author Juan
 */
public class AgeVsBraveness extends ChartModel {

    private List<Kid> kids;
    private List<List<Double>> data;

    public AgeVsBraveness() {
        
    }

    private void calculate() {
        data = new ArrayList<List<Double>>();

        for (int i = 0; i < 12; i++) {
            data.add(new ArrayList<Double>());
            data.get(i).add(0.0);
        }

        for (Kid kid : kids) {
            int age = kid.getAge();
            double braveness = kid.getBraveness();
            double oldValue = data.get(age).get(0);
            double newValue;
            if (0.0 == oldValue) {
                newValue = braveness;
            } else {
                newValue = (oldValue + braveness) / 2.0;
            }
            data.get(age).set(0, newValue);
        }
    }

    @Override
    public List<String> getGroupLabels() {
        calculate();
        List<String> x = new ArrayList<String>();
        for (int i = 0; i < data.size(); i++) {
            x.add("" + i);
        }
        return x;
    }

    @Override
    public List<String> getSeriesLabels() {
        calculate();
        List<String> x = new ArrayList<String>();
        x.add("Braveness");
        return x;
    }

    @Override
    public List<List<Double>> getYValues() {
        calculate();
        return data;
    }

    public void setKids(List<Kid> kids) {
        this.kids = kids;
    }
}